<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 点击按钮添加一行 tr -->
    td:<input type="text" id="td1" /><br />
    td2:<input type="text" id="td2" />
    <input type="button" value="添加" onclick="addBtn();" />
    <table id="tab" border="1">
      <tr>
        <td>Row1 cell1</td>
        <td>Row1 cell2</td>
      </tr>
      <tr>
        <td>Row2 cell1</td>
        <td>Row2 cell2</td>
      </tr>
    </table>
    <script>
      function addBtn() {
        var tab = document.getElementById('tab')
        //在表格中的指定位置插入新的一行
        var row = tab.insertRow(tab.rows.length)
        //创建一个新的位置，插入行的指定位置
        var cell1 = row.insertCell(0)
        cell1.innerHTML = document.getElementById('td1').value
        var cell2 = row.insertCell(1)
        cell2.innerHTML = document.getElementById('td2').value
      }
    </script>
  </body>
</html>
